package day23;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * 文本文件上传到服务端保存
 */

/**
 *
 * TextUploadClient.java
 * @author wangbiao<br/>
 *         email:785497344@qq.com
 * @description 客户端
 * @since 1.0.0
 * @date 2013-7-11下午11:28:31
 *
 */
public class TextUploadClient {

	public static void main(String[] args) {
		Socket s = null;
		BufferedReader br = null;
		try {
			s = new Socket("192.168.1.102", 10000);
			br = new BufferedReader(new FileReader("D:\\MyProject\\suckseed\\trunk\\javatest\\src\\day23\\TransClient.java"));
			//把读取的客户端文件发送到服务端
			PrintWriter out = new PrintWriter(s.getOutputStream(), true);
			String line = null;
			while ((line=br.readLine()) != null) {
				out.println(line);
			}
			//关闭客户端的输出流，相当于给流中加入结束标记-1
			s.shutdownOutput();
			
			//获取服务端反馈的信息
			BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
			String message = in.readLine();
			System.out.println("服务端的反馈信息     "+message);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (null != br) {
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (null != s) {
				try {
					s.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
